package com.idp.web.bp.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.base.BaseController;
import com.common.constant.SysMessage;
import com.common.model.JsonModel;
import com.common.model.PageModel;
import com.common.utils.ValidateUtil;
import com.idp.biz.bpsms.entity.BpSms;
import com.idp.biz.bpsms.service.BpSmsService;

 /**
 * 短信记录controller
 * 
 * @author Stone
 *
 */
@Controller
@RequestMapping("/bpSms/")
public class BpSmsController extends BaseController {
	private static Logger logger = LoggerFactory.getLogger(BpSmsController.class);

	@Autowired
	private BpSmsService bpSmsService;
	
	/**
	 * 初始化查询页面
	 * Stone 2019-06-29
	 * @return
	 */
	@RequestMapping(value="init",method=RequestMethod.GET)
	public String init(){
		logger.info("短信记录");
		return "bp/bpSms/bpSmsList";
	}
	
	/**
	 * 分页查询
	 * Stone 2019-06-29
	 * @param bpSms
	 * @param page
	 * @return
	 */
	@RequestMapping(value="list",method=RequestMethod.POST)
	@ResponseBody
	public PageModel<BpSms> list(BpSms bpSms,PageModel<BpSms> page){
		return bpSmsService.findByPage(bpSms, page);
	}

	/**
	 * 新增修改页面初始化
	 * Stone 2019-06-29
	 * @param id
	 * @param request
	 * @return
	 */
	@RequestMapping(value="bpSms",method=RequestMethod.GET)
	public String bpSms(String id,HttpServletRequest request){
		if(ValidateUtil.isNotEmpty(id)){
			BpSms bpSms = bpSmsService.getById(id);
			request.setAttribute("bpSms", bpSms);
		}
		return "bp/bpSms/bpSmsEdit";
	}
	
	/**
	 * 详情
	 * Stone 2019-06-29
	 * @param id
	 * @param request
	 * @return
	 */
	@RequestMapping(value="view",method=RequestMethod.GET)
	public String view(String id,HttpServletRequest request){
		if(ValidateUtil.isNotEmpty(id)){
			BpSms bpSms = bpSmsService.getById(id);
			request.setAttribute("bpSms", bpSms);
		}
		return "bp/bpSms/bpSmsView";
	}
	
	/**
	 * 保存
	 * Stone 2019-06-29
	 * @param bpSms
	 * @return
	 */
	@RequestMapping(value="save",method=RequestMethod.POST)
	@ResponseBody
	public JsonModel save(BpSms bpSms){
		JsonModel json = new JsonModel();
		if(ValidateUtil.isNotEmpty(bpSms.getId())){
			bpSmsService.update(bpSms);
			json.setMessage(SysMessage.COMMON_UPDATE_SUCCESS);
		} else{
			bpSmsService.add(bpSms);
			json.setMessage(SysMessage.COMMON_ADD_SUCCESS);
		}
		return json;
	}
	
	/**
	 * 删除
	 * Stone 2019-06-29
	 * @param id
	 * @return
	 */
	@RequestMapping(value="delete",method=RequestMethod.POST)
	@ResponseBody
	public JsonModel delete(String ids){
		JsonModel json = new JsonModel();
		bpSmsService.delete(ids);
		json.setMessage(SysMessage.COMMON_DELETE_SUCCESS);
		return json;
	}
}
